<template>
  <el-dialog
    :visible.sync="show"
    width="500px"
    :append-to-body="true"
    :show-close="false"
    :close-on-click-modal="false"
  >
    <div slot="title" class="title_close">
      <!-- 交易账户升级 -->
      <div class="title">{{$t('account_dialog.account_up.56hqvuz2e2g0')}}</div>
      <img
        src="@/assets/img/icon_gb1.png"
        class="close"
        @click="hideAccountUp"
      />
    </div>
    <div class="account_detail">
      <div class="title">{{$t('account_dialog.account_up.56hqvuz2fkg0')}}</div>
      <div class="content11">{{totalAmount}} <span>USD({{$t('account_dialog.account_up.56hqvu54jyc0')}})</span></div>
      <div class="tip">{{$t('account_dialog.account_up.56hqvuz2g280')}}</div>
    </div>
    <div class="updata">
      <div class="open">
        <div>{{$t('account_dialog.account_up.56hqvuz2gkc0')}}</div>
        <button v-if="IsOpen == 4" class="small-blur up_open disClick">{{$t('account_dialog.account_up.56hqvuz2gwg0')}}</button>
        <button v-else-if="Number(this.totalAmount) < 2000 " class="small-blur up_open disClick">{{$t('account_dialog.account_up.56hqvuz2hmc0')}}</button>
        <button @click="openAccount" v-else class="small-blur up_open">{{$t('account_dialog.account_up.56hqvuz2hmc0')}}</button>
      </div>
      <div class="content11" v-if="IsOpen == 4">{{$t('account_dialog.account_up.56hqvuz2hw80')}}</div>
      <div class="content11" v-else>{{$t('account_dialog.account_up.56hqvuz2i540')}}</div>
      <div class="tip">{{$t('account_dialog.account_up.56hqvuz2ie00')}}</div>
    </div>
  </el-dialog>
</template>

<script>
import {get_account_index, get_apply_finance_ccount} from '@/assets/js/API/user.js'
import {get_asset_master} from '@/assets/js/API/order.js'
export default {
  props: {
    show: Boolean,
    type: Number,
    amount: String,
  },
  data() {
    return {
      IsOpen: 4,
      totalAmount: "", // 总资产
    };
  },
  created() {},
  mounted() {
  },
  filters: {
    accountType(val) {
      switch(val) {
        case 2:
          return this.$t('account_dialog.account_up.56hqvuz2imk0')
        case 3:
          return this.$t('account_dialog.account_up.56hqvuz2iuo0')
        default:
          return this.$t('account_dialog.account_up.56hqvuqwjyc0')
      }
    },
    currentCurrency(val) {
      switch(val) {
        case 2:
          return "HKD"
        case 3:
          return "USD"
        default:
          return "HKD"
      }
    }
  },
  methods: {
    // 关闭升级账户接口
    hideAccountUp() {
      this.$emit("closeUp");
    },
    // 获取账户总资产
    async getTotalAccount() {
      if(this.IsOpen == 0 || this.IsOpen == 2 || this.IsOpen == 3) return;
      const res = await get_asset_master( {
          currency: "USD"
        });
      if(res.code != 1) return this.$message.error(res.msg);
      this.totalAmount = res.data.totalAsset;
    },
    // 开动融资账户
    async openAccount() {
      const confirmInfo = await this.$confirm(this.$t('account_dialog.account_up.56hqvuz2j3c0'),
        this.$t('account_dialog.account_up.56hqvuz2jg80'),
        {
          confirmButtonText: this.$t('account_dialog.account_up.56hqvuz2jpk0'),
          cancelButtonText: this.$t('account_dialog.account_up.56hqvuz2jyc0'),
          type: "warning",
        }
      ).catch((err) => err);
      if (confirmInfo !== "confirm")
        return this.$message.info(this.$t('account_dialog.account_up.56hqvuz2k6s0'));
      const res = await get_apply_finance_ccount();
      if(res.code != 1) return this.$message.error(res.msg);
      this.hideAccountUp();
      return this.$message.success(res.msg);
    },
    // 得到当前开户状态
    async getInfo() {
      const res = await get_account_index();
      if(res.code != 1) return this.$message.error(res.msg);
      this.IsOpen = res.data.isOpen;
      sessionStorage.setItem("isOpen", this.IsOpen);
    }
  }
};
</script>
<style lang="less">
@import "~@/assets/less/common.less";
.account_detail {
  background: no-repeat;
  background-size: 440px 130px;
  background-image: url("~@/assets/img/bzzhd@2x.png");
  height: 130px;
  // margin-top: 10px;
  // margin-bottom: 20px;
  color: @fff;
  padding: 20px 0 0 20px;
}
.updata {
  background: no-repeat;
  background-size: 440px 130px;
  background-image: url("~@/assets/img/rzzhd@2x.png");
  height: 130px;
  color: @fff;
  padding: 20px 0 0 20px;
}
.title {
  font-size: 14px;
}
.content11 {
  font-size: 24px;
  span{
    font-size: 12px;
  }
}
.tip {
  font-size: 12px;
}
.open {
  display: flex;
  justify-content: space-between;
  align-items: center;
  .up_open {
    width: 60px;
    margin-right: 20px;
    background-color: #15BCE3 !important;
  }
}
.disClick {
  cursor: not-allowed;
}
</style>